---
title: Leverage a Geoprocessing Service
description: This demo relies on the <a href="https://github.com/jgravois/esri-leaflet-gp/">Esri Leaflet GP</a> plugin.<br>More information about Geoprocessing Services can be found in the <a href="http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/GP_Service/02r3000000rq000000/">ArcGIS REST</a> documentation.
layout: example.hbs
---

<!-- load the latest release from the cdn automatically -->
<script src="https://unpkg.com/esri-leaflet-gp"></script>

<style>
  #info-pane {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1000;
    padding: 1em;
    background: white;
  }
</style>

<div id="map"></div>
<div id="info-pane" class="leaflet-bar">
  <label>
  click on the map to calculate<br>1 and 2 minute drivetime polygons
  </label>
</div>

<script type='text/javascript'>
  var map = L.map('map').setView([37.78, -122.42], 12);

  L.esri.basemapLayer('Gray').addTo(map);

  var gpService = L.esri.GP.service({
    url: "https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Network/ESRI_DriveTime_US/GPServer/CreateDriveTimePolygons",
    useCors:false
  });

  var gpTask = gpService.createTask();

  gpTask.setParam("Drive_Times", "1 2");

  var driveTimes = L.featureGroup();
  map.addLayer(driveTimes);

  map.on('click', function(evt){
    document.getElementById('info-pane').innerHTML = 'working...';
    driveTimes.clearLayers();
    gpTask.setParam("Input_Location", evt.latlng)
    gpTask.run(driveTimeCallback);
  });

  function driveTimeCallback(error, response, raw){
    document.getElementById('info-pane').innerHTML = 'click on the map to calculate 1 and 2 minute drivetimes';
    driveTimes.addLayer(L.geoJSON(response.Output_Drive_Time_Polygons));
  }
</script>
